<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2023-10-13
 * Time: 20:57:52
 * Info:
 */

namespace plugin\huiblog\app\model;

use think\Model;
use support\Cache;

class Links extends Model
{

    protected $table = 'blog_links';

    /**
     * 自动时间戳类型
     * @var string
     */
    protected $autoWriteTimestamp = true;

    /**
     * 添加时间
     * @var string
     */
    protected $createTime = 'create_time';

    /**
     * 更新时间
     * @var string
     */
    protected $updateTime = 'update_time';

    //获取列表，前端模版标签使用
    public function getList($limit = 10, $logo = 0, $order = 'sort asc')
    {
        if (Cache::get('cacheBlogLinks')) {
            $res = Cache::get('cacheBlogLinks');
        } else {
            $res = Links::where(['status' => 1])->where(function ($query) use ($logo) {
                if ($logo) {
                    $query->where('logo', '<>', '');
                }
            })->order($order)->limit($limit)->select();
            Cache::set('cacheBlogLinks', $res);
        }

        return $res;
    }

}
